package com.woniuxy.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.woniuxy.dao.InspectionRecordMapper;
import com.woniuxy.pojo.InspectionRecord;
import com.woniuxy.service.InspectionRecordService;
import com.woniuxy.util.DataGridView;
import com.woniuxy.vo.InspectionRecordVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class InspectionRecordServiceImpl implements InspectionRecordService {
    @Autowired
    InspectionRecordMapper inspectionRecordMapper;

    @Override
    public DataGridView findByPage(InspectionRecordVo inspectionRecordVo) {
        Page<Object> page= PageHelper.startPage(inspectionRecordVo.getPage(),inspectionRecordVo.getLimit());
        List<InspectionRecord> list=inspectionRecordMapper.selectByCondition(inspectionRecordVo);
        return new DataGridView(page.getTotal(),list);
    }

    @Override
    public boolean add(InspectionRecord inspectionRecord) {
        int res = inspectionRecordMapper.insert(inspectionRecord);
        if(res>0){
            return true;
        }
        return false;
    }

    @Override
    public boolean update(InspectionRecord inspectionRecord) {
        int res = inspectionRecordMapper.update(inspectionRecord);
        if(res>0){
            return true;
        }
        return false;
    }

    @Override
    public boolean removeById(int id) {
        inspectionRecordMapper.deleteById(id);
        return true;
    }

    @Transactional
    @Override
    public void removeBatch(Integer[] ids) {
        if(ids.length>0){
            for(Integer id:ids){
                this.removeById(id);
            }
        }
    }
}
